/*
前馈神经网络测试套件
验证神经网络各组件功能和整体性能
包含单元测试和集成测试
*/
#include <vector>
#include <iostream>
#include "NeuralNetwork.h"

void testXOR() {
    std::vector<int> topology = {2, 4, 1};
    NeuralNetwork nn(topology, 0.5, 0.09);
    std::cout << "Initial Neural Network Done:" << std::endl;
    nn.print();

    std::vector<std::vector<double> > inputs = {
        {0, 0},
        {0, 1},
        {1, 0},
        {1, 1}
    };
    std::vector<std::vector<double> > targets = {
        {0},
        {1},
        {1},
        {0}
    };

    // Train the network
    for (int epoch = 0; epoch < 500; ++epoch) {
        for (size_t i = 0; i < inputs.size(); ++i) {
            std::cout << "==========================" << std::endl;
            std::cout << "Epoch " << epoch + 1 << ", Sample " << i + 1 << std::endl;
            std::cout << "Input: " << inputs[i][0] << ", " << inputs[i][1] << std::endl;
            nn.feedForward(inputs[i]);
            std::cout << "Output: " << nn.getOutput()[0] << std::endl;
            std::cout << "Target: " << targets[i][0] << std::endl;
            nn.backPropagate(targets[i]);
            nn.calculateGradients();
            nn.updateWeights();
            std::cout << "After updateWeights:" << std::endl;
            nn.print();
        }
    }

    // Test the network
    for (const auto& input : inputs) {
        nn.feedForward(input);
        std::vector<double> output = nn.getOutput();
        std::cout << "Input: [" << input[0] << ", " << input[1] << "] -> Output: " << output[0] << std::endl;
    }
}

int main() {
    testXOR();
    return 0;
}